package com.css.fxfzxczh.modules.fastDisasterAnalysis.houseDestroy.controller;

import com.css.fxfzxczh.base.response.RestResponse;
import com.css.fxfzxczh.modules.fastDisasterAnalysis.casualties.param.EvaluateParam;
import com.css.fxfzxczh.modules.fastDisasterAnalysis.houseDestroy.param.HouseEvaluateParam;
import com.css.fxfzxczh.modules.fastDisasterAnalysis.houseDestroy.service.HouseDestroyService;
import com.css.fxfzxczh.util.ResponseCreator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Dbj
 * @date 2023年07月28日  14:28
 * 房屋破坏评估
 */
@RestController
@RequestMapping("/houseDestroy")
public class HouseDestroyController {

    @Resource
    HouseDestroyService houseDestroyService;
    /**
     * 房屋破坏评估计算
     */
    @PostMapping("/evaluate")
    public RestResponse evaluate(@RequestBody EvaluateParam param) throws Exception {
        System.out.println("房屋破坏评估第2步开始");
        Long start = System.currentTimeMillis();
        if(StringUtils.isBlank(param.getXsemId())){
            throw new RuntimeException("评估失败,请选择要评估的地震事件");
        }
        if(StringUtils.isBlank(param.getBuildingVersion())){
            throw new RuntimeException("评估失败,请选择建筑物数据版本");
        }
        if(StringUtils.isBlank(param.getInfluenceVersion()) || StringUtils.isBlank(param.getFvId())){
            throw new RuntimeException("评估失败,请选择影响场数据版本");
        }
        houseDestroyService.evaluate(param);
        System.out.println("房屋破坏评估第2步结束，花费时间"+((System.currentTimeMillis()-start)/1000));
        return ResponseCreator.createSuccessResponse("","评估计算完成");
    }

    /**
     * 计算各烈度下各类建筑物的破坏面积
     * @param evaluateParam
     * @return
     */
    @PostMapping("/countIntensityAndStructureOfArea")
    public RestResponse countIntensityAndStructureOfArea(@RequestBody HouseEvaluateParam evaluateParam) throws Exception{
        System.out.println("房屋破坏评估第一步开始");
        Long start = System.currentTimeMillis();
        if(StringUtils.isBlank(evaluateParam.getBuildingVersion())){
            throw new RuntimeException("评估失败,请选择建筑物数据版本");
        }
        if(StringUtils.isBlank(evaluateParam.getInfluenceVersion()) || StringUtils.isBlank(evaluateParam.getFvId())){
            throw new RuntimeException("评估失败,请选择影响场数据版本");
        }
        RestResponse restResponse = houseDestroyService.countIntensityAndStructureOfArea(evaluateParam);
        System.out.println("房屋破坏评估第一步结束，花费时间"+((System.currentTimeMillis()-start)/1000));
        return restResponse;
    }

    /**
     * 查看房屋破坏评估结果
     * @param  xsemId 事件id
     */
    @GetMapping("/getHouseDestoryResult")
    public RestResponse getHouseDestoryResult(@RequestParam String xsemId,@RequestParam String dzIntensity){
        return houseDestroyService.getHouseDestoryResult(xsemId,dzIntensity);
    }


    /**
     * 查看当前地震事件下五种烈度的房屋破坏面积
     * @param  xsemId 事件id
     */
    @GetMapping("/getHouseDestoryAreaSum")
    public RestResponse getHouseDestoryAreaSum(@RequestParam String xsemId){
        return houseDestroyService.getHouseDestoryAreaSum(xsemId);
    }

    @GetMapping("/getModelData")
    public RestResponse getModelData(@RequestParam String xsemId ){
        return ResponseCreator.createSuccessResponse(houseDestroyService.getModelData(xsemId));
    }
}
